import java.io.EOFException;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;


public class StringHolder2 implements Externalizable{
	
	StringBinTree root = null;
    
	
	public void addString(String s) {
		root = StringBinTree.tree_AddString(root,s);
	}
	
	public void printInOrder() {
		root.tree_InOrderPrint(root);
	}
	
	public boolean isEqual(StringHolder2 to){
		return StringBinTree.tree_Compare(root, to.root);
	}

	@Override
	public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
		System.out.println("\nExternalizable Reader called");
		root = null;
		try {
			while (true){
				String data = in.readUTF();
				//System.out.println(data);
				addString(data);
			}
		} catch (EOFException e) { 
			// Do nothing here.  End of file hit
		}
	}

	@Override
	public void writeExternal(ObjectOutput out) throws IOException {
	    System.out.println("Externalizable Writer called");
	    root.tree_Serialize(root, out);		
	}

}
